import confige from "./confige.js";

export const myRequest = (options) =>{
	return new Promise((resolve,reject)=>{
		uni.request({
			url:confige.webUrl+options.url,
			method:options.method || "GET",
			data:options.data || {},
			header:options.header || {},
			success: (res) => {
				if(res.data.code == 401){
					// console.log(111);
					uni.showToast({
						title:"登录已失效，请重新登录",
						icon:"none"
					});
					uni.redirectTo({
						url: "../userLogin/userLogin"
					});
					this.token = false;
					uni.removeStorageSync('token');
					return false ;
				}
				resolve(res)
			},
			fail: (err) => {
				console.log(err)
				uni.showToast({
					title:"接口请求失败",
					icon:"none"
				})
				reject(err);
			}
		})
	}
	)
}
